// Copyright Epic Games, Inc. All Rights Reserved.


#include "TowerDefenceGameModeBase.h"

#include "Generation/Content/Architect.h"
#include "Generation/Piecemeal/FArray2D.h"
#include "Generation/Piecemeal/Rect.h"
#include "System/GameConfiguration.h"
#include "TD/CubeTest.h"

void ATowerDefenceGameModeBase::BeginPlay()
{
	Super::BeginPlay();

	// FRect myRect(0, 0, 4, 5);
	// for (auto x : myRect)
	// {
	// 	UE_LOG(LogTD, Error, TEXT("In x: %d y: %d"), x.x, x.y);
	// }
	//
	// FArray2D<int> arr(3,4);
	// FRect rect = *arr.bounds;
	// for (auto x : rect)
	// {
	// 	UE_LOG(LogTD, Error, TEXT("In2 x: %d y: %d"), x.x, x.y);
	// }

	Architect a;
	FStage* stage = new FStage(20, 20);
	a.InitStage(stage);
	a.Rebuild(1, 10, 3, 9);

	// 绘制
	auto bounds = *(a.stage->Bounds());
	for (auto pos : bounds)
	{
		auto tileType = stage->Get(&pos)->type;

		if (tileType == FTileType::solid)
		{
			ACubeTest* SpawnedActor1 = GetWorld()->SpawnActor<ACubeTest>(unreachable);
			SpawnedActor1->GetTransform().GetLocation().Set(pos.x, 0, pos.y);
		}
		else if (tileType == FTileType::solidWet)
		{
			ACubeTest* SpawnedActor1 = GetWorld()->SpawnActor<ACubeTest>(passage);
			SpawnedActor1->GetTransform().GetLocation().Set(pos.x, 0, pos.y);
		}
		else if (tileType == FTileType::open)
		{
			ACubeTest* SpawnedActor1 = GetWorld()->SpawnActor<ACubeTest>(room);
			SpawnedActor1->GetTransform().GetLocation().Set(pos.x, 0, pos.y);
		}
		else if (tileType == FTileType::unformed)
		{
			ACubeTest* SpawnedActor1 = GetWorld()->SpawnActor<ACubeTest>(unreachable);
			SpawnedActor1->GetTransform().GetLocation().Set(pos.x, 0, pos.y);
		}
	}

	// FTransform* trans = new FTransform();
	// ACubeTest* SpawnedActor1 = GetWorld()->SpawnActor<ACubeTest>();
	// SpawnedActor1->GetTransform().GetLocation().Set(0, 0, 1);

	// FActorSpawnParameters Parameters;
	// Parameters.Template = passage.GetDefaultObject();
}
